package com.cvmars.jianyou.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.View;

import com.cvmars.jianyou.R;

import static android.graphics.Paint.ANTI_ALIAS_FLAG;

/**
 * Created by hehaifeng on 2018/11/29.
 */

public class MoiveView extends View {

    private final Paint polygonFillPaint = new Paint(ANTI_ALIAS_FLAG);
    private final Paint polygonStrokePaint = new Paint(ANTI_ALIAS_FLAG);
    private final float strokeWidth = getResources().getDimension(R.dimen.stroke_width);

    private int numberOfSides = 3;
    private float cornerRadius = 120;
    private float rotation = 0;
    private float scale;

    private final Path strokePath = new Path();

    public MoiveView(final Context context, @Nullable final AttributeSet attrs) {
        super(context, attrs);

        polygonFillPaint.setColor(ContextCompat.getColor(context, R.color.A400));
        polygonFillPaint.setStyle(Paint.Style.FILL);

        polygonStrokePaint.setColor(ContextCompat.getColor(context, R.color.colorAccent));
        polygonStrokePaint.setStrokeWidth(strokeWidth);
        polygonStrokePaint.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onDraw(final Canvas canvas) {
        super.onDraw(canvas);

        final float centerX = getWidth() / 2;
        final float centerY = getHeight() / 2;
        final float radius = scale * (getWidth() / 2 - strokeWidth);



        canvas.drawPath(strokePath, polygonStrokePaint);
    }

    public int getNumberOfSides() {
        return numberOfSides;
    }

    public void setNumberOfSides(final int numberOfSides) {
        this.numberOfSides = numberOfSides;
        invalidate();
    }

    public void setCornerRadius(final float cornerRadius) {
        this.cornerRadius = cornerRadius;
        invalidate();
    }

    public void setPolygonRotation(final float rotation) {
        this.rotation = rotation;
        invalidate();
    }

    public void setScale(final float scale) {
        this.scale = scale;
        invalidate();
    }
}
